﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using VoteUphold;
using System.Net;
using System.Threading;

namespace Vote
{
    public partial class Form3 : Form
    {
        public Form3()
        {
            InitializeComponent();
        }


        VUvote vu = null;

        private void Form3_Load(object sender, EventArgs e)
        {
            this.txtName.Text = "admin";
            this.txtPwd.Text = "admin";
            vu = new VUvote(new VoteUrl(adressVoteShow: "http://www.heixiaotu.net/index.asp",

                adressVoteSend: "http://www.heixiaotu.net/checkuserlogin.asp",
                adressCode: "http://www.heixiaotu.net/GetCode.asp"));

            byte[] responseData = vu.httpClient.DownloadData(vu.voteUrl.AdressVoteShow);
            string srcString = Encoding.GetEncoding("gb2312").GetString(responseData);
            GetRand();
        }

        private void pictureBox1_Click_1(object sender, EventArgs e)
        {
            GetRand();
        }
        private void button2_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < 1; i++)
            {
                Thread t = new Thread(new ThreadStart(NewMethod));
                t.Start();
            }
        }

        private void NewMethod()
        {
            //HttpClient hc = new HttpClient(new Uri(vu.voteUrl.AdressVoteShow));
            while (true)
            {
                try
                {
                    string postData = "username=feiazi&userpassword=11111&linkaddress2=&verifycode=" + 
                        this.textBox1.Text.Trim()
                    + "&imageField.x=28&imageField.y=3";
                    //<script LANGUAGE='javascript'>alert('请输入正确的验证码！');history.go(-1);window.location.href='index.asp'</script>
                    //<script LANGUAGE='javascript'>alert('对不起！您的用户名或密码有误！');history.go(-1);window.location.href='index.asp'</script>

                    string s = vu.httpClient.PostData(vu.voteUrl.AdressVoteSend,
                        postData, Encoding.GetEncoding("gb2312"), Encoding.GetEncoding("gb2312"));
                    if (s.Contains("您的用户名或密码有误"))
                    {

                    }
                    else if (s.Contains("请输入正确的验证码"))
                    {

                    }
                    else
                    {

                    }
                }
                catch (Exception ee)
                {
                }
            }
        }

        private void pictureBox1_Click(object sender, EventArgs e)
        {
            GetRand();
        }

        private void GetRand()
        {
            if (File.Exists("szz.gif"))
            {
                File.Delete("szz.gif");
            }
            vu.httpClient.DownloadFile(new Uri(vu.voteUrl.AdressCode), "szz.gif");
            FileInfo fi = new FileInfo("szz.gif");
            if (fi != null)
            {
                fi.Attributes = FileAttributes.Hidden;
            }
            pictureBox1.LoadAsync("szz.gif");
        }

        
    }
}
